
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta charset="utf-8" />
  
  <!-- Licensed under the Apache 2.0 License -->
  <link rel="stylesheet" type="text/css" href="../../../../_static/fonts/open-sans/stylesheet.css" />
  <!-- Licensed under the SIL Open Font License -->
  <link rel="stylesheet" type="text/css" href="../../../../_static/fonts/source-serif-pro/source-serif-pro.css" />
  <link rel="stylesheet" type="text/css" href="../../../../_static/css/bootstrap.min.css" />
  <link rel="stylesheet" type="text/css" href="../../../../_static/css/bootstrap-theme.min.css" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
    <title>jmetal.algorithm.multiobjective.moead &#8212; jMetalPy 1.5.1 documentation</title>
    <link rel="stylesheet" href="../../../../_static/guzzle.css" type="text/css" />
    <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
    <link rel="stylesheet" type="text/css" href="../../../../_static/custom.css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../../../_static/language_data.js"></script>
    <script async="async" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="author" title="About these documents" href="../../../../about.html" />
    <link rel="index" title="Index" href="../../../../genindex.html" />
    <link rel="search" title="Search" href="../../../../search.html" />
  
   

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">jMetalPy 1.5.1 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" accesskey="U">Module code</a> &#187;</li> 
      </ul>
    </div>
    <div class="container-wrapper">

      <div id="mobile-toggle">
        <a href="#"><span class="glyphicon glyphicon-align-justify" aria-hidden="true"></span></a>
      </div>
  <div id="left-column">
    <div class="sphinxsidebar"><a href="
    ../../../../index.html" class="text-logo">jMetalPy</a>
<div class="sidebar-block">
  <div class="sidebar-wrapper">
    <h2>Table Of Contents</h2>
  </div>
  <div class="sidebar-toc">
    
    
      <ul>
<li class="toctree-l1"><a class="reference internal" href="../../../../tutorials.html">Getting started</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../multiobjective.algorithms.html">Multi-objective algorithms</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../singleobjective.algorithms.html">Single-objective algorithms</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../operators.html">Operators</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../problems.html">Problems</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../contributing.html">Contributing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../about.html">About</a></li>
</ul>

    
  </div>
</div>
<div class="sidebar-block">
  <div class="sidebar-wrapper">
    <div id="main-search">
      <form class="form-inline" action="../../../../search.html" method="GET" role="form">
        <div class="input-group">
          <input name="q" type="text" class="form-control" placeholder="Search...">
        </div>
        <input type="hidden" name="check_keywords" value="yes" />
        <input type="hidden" name="area" value="default" />
      </form>
    </div>
  </div>
</div>
      
    </div>
  </div>
        <div id="right-column">
          
          <div role="navigation" aria-label="breadcrumbs navigation">
            <ol class="breadcrumb">
              <li><a href="../../../../index.html">Docs</a></li>
              
                <li><a href="../../../index.html">Module code</a></li>
              
              <li>jmetal.algorithm.multiobjective.moead</li>
            </ol>
          </div>
          
          <div class="document clearer body">
            
  <h1>Source code for jmetal.algorithm.multiobjective.moead</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">copy</span>
<span class="kn">import</span> <span class="nn">random</span>
<span class="kn">from</span> <span class="nn">math</span> <span class="k">import</span> <span class="n">ceil</span>
<span class="kn">from</span> <span class="nn">typing</span> <span class="k">import</span> <span class="n">TypeVar</span><span class="p">,</span> <span class="n">List</span>

<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>

<span class="kn">from</span> <span class="nn">jmetal.algorithm.singleobjective.genetic_algorithm</span> <span class="k">import</span> <span class="n">GeneticAlgorithm</span>
<span class="kn">from</span> <span class="nn">jmetal.config</span> <span class="k">import</span> <span class="n">store</span>
<span class="kn">from</span> <span class="nn">jmetal.core.operator</span> <span class="k">import</span> <span class="n">Mutation</span>
<span class="kn">from</span> <span class="nn">jmetal.core.problem</span> <span class="k">import</span> <span class="n">Problem</span>
<span class="kn">from</span> <span class="nn">jmetal.operator</span> <span class="k">import</span> <span class="n">DifferentialEvolutionCrossover</span><span class="p">,</span> <span class="n">NaryRandomSolutionSelection</span>
<span class="kn">from</span> <span class="nn">jmetal.util.aggregative_function</span> <span class="k">import</span> <span class="n">AggregativeFunction</span>
<span class="kn">from</span> <span class="nn">jmetal.util.constraint_handling</span> <span class="k">import</span> <span class="n">feasibility_ratio</span><span class="p">,</span> \
    <span class="n">overall_constraint_violation_degree</span><span class="p">,</span> <span class="n">is_feasible</span>
<span class="kn">from</span> <span class="nn">jmetal.util.density_estimator</span> <span class="k">import</span> <span class="n">CrowdingDistance</span>
<span class="kn">from</span> <span class="nn">jmetal.util.neighborhood</span> <span class="k">import</span> <span class="n">WeightVectorNeighborhood</span>
<span class="kn">from</span> <span class="nn">jmetal.util.ranking</span> <span class="k">import</span> <span class="n">FastNonDominatedRanking</span>
<span class="kn">from</span> <span class="nn">jmetal.util.solutions</span> <span class="k">import</span> <span class="n">Evaluator</span><span class="p">,</span> <span class="n">Generator</span>
<span class="kn">from</span> <span class="nn">jmetal.util.termination_criterion</span> <span class="k">import</span> <span class="n">TerminationCriterion</span><span class="p">,</span> <span class="n">StoppingByEvaluations</span>

<span class="n">S</span> <span class="o">=</span> <span class="n">TypeVar</span><span class="p">(</span><span class="s1">&#39;S&#39;</span><span class="p">)</span>
<span class="n">R</span> <span class="o">=</span> <span class="n">List</span><span class="p">[</span><span class="n">S</span><span class="p">]</span>


<div class="viewcode-block" id="MOEAD"><a class="viewcode-back" href="../../../../api/algorithm/multiobjective/eas/moead.html#jmetal.algorithm.multiobjective.moead.MOEAD">[docs]</a><span class="k">class</span> <span class="nc">MOEAD</span><span class="p">(</span><span class="n">GeneticAlgorithm</span><span class="p">):</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
                 <span class="n">problem</span><span class="p">:</span> <span class="n">Problem</span><span class="p">,</span>
                 <span class="n">population_size</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span>
                 <span class="n">mutation</span><span class="p">:</span> <span class="n">Mutation</span><span class="p">,</span>
                 <span class="n">crossover</span><span class="p">:</span> <span class="n">DifferentialEvolutionCrossover</span><span class="p">,</span>
                 <span class="n">aggregative_function</span><span class="p">:</span> <span class="n">AggregativeFunction</span><span class="p">,</span>
                 <span class="n">neighbourhood_selection_probability</span><span class="p">:</span> <span class="nb">float</span><span class="p">,</span>
                 <span class="n">max_number_of_replaced_solutions</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span>
                 <span class="n">neighbor_size</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span>
                 <span class="n">weight_files_path</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
                 <span class="n">termination_criterion</span><span class="p">:</span> <span class="n">TerminationCriterion</span> <span class="o">=</span> <span class="n">store</span><span class="o">.</span><span class="n">default_termination_criteria</span><span class="p">,</span>
                 <span class="n">population_generator</span><span class="p">:</span> <span class="n">Generator</span> <span class="o">=</span> <span class="n">store</span><span class="o">.</span><span class="n">default_generator</span><span class="p">,</span>
                 <span class="n">population_evaluator</span><span class="p">:</span> <span class="n">Evaluator</span> <span class="o">=</span> <span class="n">store</span><span class="o">.</span><span class="n">default_evaluator</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :param max_number_of_replaced_solutions: (eta in Zhang &amp; Li paper).</span>
<span class="sd">        :param neighbourhood_selection_probability: Probability of mating with a solution in the neighborhood rather</span>
<span class="sd">               than the entire population (Delta in Zhang &amp; Li paper).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">MOEAD</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span>
            <span class="n">problem</span><span class="o">=</span><span class="n">problem</span><span class="p">,</span>
            <span class="n">population_size</span><span class="o">=</span><span class="n">population_size</span><span class="p">,</span>
            <span class="n">offspring_population_size</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
            <span class="n">mutation</span><span class="o">=</span><span class="n">mutation</span><span class="p">,</span>
            <span class="n">crossover</span><span class="o">=</span><span class="n">crossover</span><span class="p">,</span>
            <span class="n">selection</span><span class="o">=</span><span class="n">NaryRandomSolutionSelection</span><span class="p">(</span><span class="mi">2</span><span class="p">),</span>
            <span class="n">population_evaluator</span><span class="o">=</span><span class="n">population_evaluator</span><span class="p">,</span>
            <span class="n">population_generator</span><span class="o">=</span><span class="n">population_generator</span><span class="p">,</span>
            <span class="n">termination_criterion</span><span class="o">=</span><span class="n">termination_criterion</span>
        <span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">max_number_of_replaced_solutions</span> <span class="o">=</span> <span class="n">max_number_of_replaced_solutions</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">fitness_function</span> <span class="o">=</span> <span class="n">aggregative_function</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">neighbourhood</span> <span class="o">=</span> <span class="n">WeightVectorNeighborhood</span><span class="p">(</span>
            <span class="n">number_of_weight_vectors</span><span class="o">=</span><span class="n">population_size</span><span class="p">,</span>
            <span class="n">neighborhood_size</span><span class="o">=</span><span class="n">neighbor_size</span><span class="p">,</span>
            <span class="n">weight_vector_size</span><span class="o">=</span><span class="n">problem</span><span class="o">.</span><span class="n">number_of_objectives</span><span class="p">,</span>
            <span class="n">weights_path</span><span class="o">=</span><span class="n">weight_files_path</span>
        <span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">neighbourhood_selection_probability</span> <span class="o">=</span> <span class="n">neighbourhood_selection_probability</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">permutation</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">current_subproblem</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">neighbor_type</span> <span class="o">=</span> <span class="kc">None</span>

<div class="viewcode-block" id="MOEAD.init_progress"><a class="viewcode-back" href="../../../../api/algorithm/multiobjective/eas/moead.html#jmetal.algorithm.multiobjective.moead.MOEAD.init_progress">[docs]</a>    <span class="k">def</span> <span class="nf">init_progress</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">evaluations</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">population_size</span>
        <span class="k">for</span> <span class="n">solution</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">solutions</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">fitness_function</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">solution</span><span class="o">.</span><span class="n">objectives</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">permutation</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">population_size</span><span class="p">)</span>

        <span class="n">observable_data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_observable_data</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">observable</span><span class="o">.</span><span class="n">notify_all</span><span class="p">(</span><span class="o">**</span><span class="n">observable_data</span><span class="p">)</span></div>

<div class="viewcode-block" id="MOEAD.selection"><a class="viewcode-back" href="../../../../api/algorithm/multiobjective/eas/moead.html#jmetal.algorithm.multiobjective.moead.MOEAD.selection">[docs]</a>    <span class="k">def</span> <span class="nf">selection</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">population</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="n">S</span><span class="p">]):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">current_subproblem</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">permutation</span><span class="o">.</span><span class="n">get_next_value</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">neighbor_type</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">choose_neighbor_type</span><span class="p">()</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">neighbor_type</span> <span class="o">==</span> <span class="s1">&#39;NEIGHBOR&#39;</span><span class="p">:</span>
            <span class="n">neighbors</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">neighbourhood</span><span class="o">.</span><span class="n">get_neighbors</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">current_subproblem</span><span class="p">,</span> <span class="n">population</span><span class="p">)</span>
            <span class="n">mating_population</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">selection_operator</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="n">neighbors</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">mating_population</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">selection_operator</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="n">population</span><span class="p">)</span>

        <span class="n">mating_population</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">population</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">current_subproblem</span><span class="p">])</span>

        <span class="k">return</span> <span class="n">mating_population</span></div>

<div class="viewcode-block" id="MOEAD.reproduction"><a class="viewcode-back" href="../../../../api/algorithm/multiobjective/eas/moead.html#jmetal.algorithm.multiobjective.moead.MOEAD.reproduction">[docs]</a>    <span class="k">def</span> <span class="nf">reproduction</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">mating_population</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="n">S</span><span class="p">])</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">S</span><span class="p">]:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">crossover_operator</span><span class="o">.</span><span class="n">current_individual</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">solutions</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">current_subproblem</span><span class="p">]</span>

        <span class="n">offspring_population</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">crossover_operator</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="n">mating_population</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mutation_operator</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="n">offspring_population</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>

        <span class="k">return</span> <span class="n">offspring_population</span></div>

<div class="viewcode-block" id="MOEAD.replacement"><a class="viewcode-back" href="../../../../api/algorithm/multiobjective/eas/moead.html#jmetal.algorithm.multiobjective.moead.MOEAD.replacement">[docs]</a>    <span class="k">def</span> <span class="nf">replacement</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">population</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="n">S</span><span class="p">],</span> <span class="n">offspring_population</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="n">S</span><span class="p">])</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">S</span><span class="p">]:</span>
        <span class="n">new_solution</span> <span class="o">=</span> <span class="n">offspring_population</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">fitness_function</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">new_solution</span><span class="o">.</span><span class="n">objectives</span><span class="p">)</span>

        <span class="n">new_population</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">update_current_subproblem_neighborhood</span><span class="p">(</span><span class="n">new_solution</span><span class="p">,</span> <span class="n">population</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">new_population</span></div>

<div class="viewcode-block" id="MOEAD.update_current_subproblem_neighborhood"><a class="viewcode-back" href="../../../../api/algorithm/multiobjective/eas/moead.html#jmetal.algorithm.multiobjective.moead.MOEAD.update_current_subproblem_neighborhood">[docs]</a>    <span class="k">def</span> <span class="nf">update_current_subproblem_neighborhood</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">new_solution</span><span class="p">,</span> <span class="n">population</span><span class="p">):</span>
        <span class="n">permuted_neighbors_indexes</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">generate_permutation_of_neighbors</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">current_subproblem</span><span class="p">)</span>
        <span class="n">replacements</span> <span class="o">=</span> <span class="mi">0</span>

        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">permuted_neighbors_indexes</span><span class="p">)):</span>
            <span class="n">k</span> <span class="o">=</span> <span class="n">permuted_neighbors_indexes</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>

            <span class="n">f1</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">fitness_function</span><span class="o">.</span><span class="n">compute</span><span class="p">(</span><span class="n">population</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">.</span><span class="n">objectives</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">neighbourhood</span><span class="o">.</span><span class="n">weight_vectors</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
            <span class="n">f2</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">fitness_function</span><span class="o">.</span><span class="n">compute</span><span class="p">(</span><span class="n">new_solution</span><span class="o">.</span><span class="n">objectives</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">neighbourhood</span><span class="o">.</span><span class="n">weight_vectors</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>

            <span class="k">if</span> <span class="n">f2</span> <span class="o">&lt;</span> <span class="n">f1</span><span class="p">:</span>
                <span class="n">population</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">(</span><span class="n">new_solution</span><span class="p">)</span>
                <span class="n">replacements</span> <span class="o">+=</span> <span class="mi">1</span>

            <span class="k">if</span> <span class="n">replacements</span> <span class="o">&gt;=</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_number_of_replaced_solutions</span><span class="p">:</span>
                <span class="k">break</span>

        <span class="k">return</span> <span class="n">population</span></div>

<div class="viewcode-block" id="MOEAD.generate_permutation_of_neighbors"><a class="viewcode-back" href="../../../../api/algorithm/multiobjective/eas/moead.html#jmetal.algorithm.multiobjective.moead.MOEAD.generate_permutation_of_neighbors">[docs]</a>    <span class="k">def</span> <span class="nf">generate_permutation_of_neighbors</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">subproblem_id</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">neighbor_type</span> <span class="o">==</span> <span class="s1">&#39;NEIGHBOR&#39;</span><span class="p">:</span>
            <span class="n">neighbors</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">neighbourhood</span><span class="o">.</span><span class="n">get_neighborhood</span><span class="p">()[</span><span class="n">subproblem_id</span><span class="p">]</span>
            <span class="n">permuted_array</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">(</span><span class="n">neighbors</span><span class="o">.</span><span class="n">tolist</span><span class="p">())</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">permuted_array</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">population_size</span><span class="p">)</span><span class="o">.</span><span class="n">get_permutation</span><span class="p">()</span>

        <span class="k">return</span> <span class="n">permuted_array</span></div>

<div class="viewcode-block" id="MOEAD.choose_neighbor_type"><a class="viewcode-back" href="../../../../api/algorithm/multiobjective/eas/moead.html#jmetal.algorithm.multiobjective.moead.MOEAD.choose_neighbor_type">[docs]</a>    <span class="k">def</span> <span class="nf">choose_neighbor_type</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">rnd</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">()</span>

        <span class="k">if</span> <span class="n">rnd</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">neighbourhood_selection_probability</span><span class="p">:</span>
            <span class="n">neighbor_type</span> <span class="o">=</span> <span class="s1">&#39;NEIGHBOR&#39;</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">neighbor_type</span> <span class="o">=</span> <span class="s1">&#39;POPULATION&#39;</span>

        <span class="k">return</span> <span class="n">neighbor_type</span></div>

<div class="viewcode-block" id="MOEAD.get_name"><a class="viewcode-back" href="../../../../api/algorithm/multiobjective/eas/moead.html#jmetal.algorithm.multiobjective.moead.MOEAD.get_name">[docs]</a>    <span class="k">def</span> <span class="nf">get_name</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s1">&#39;MOEAD&#39;</span></div>

<div class="viewcode-block" id="MOEAD.get_result"><a class="viewcode-back" href="../../../../api/algorithm/multiobjective/eas/moead.html#jmetal.algorithm.multiobjective.moead.MOEAD.get_result">[docs]</a>    <span class="k">def</span> <span class="nf">get_result</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">solutions</span></div></div>


<div class="viewcode-block" id="MOEAD_DRA"><a class="viewcode-back" href="../../../../api/algorithm/multiobjective/eas/moead.html#jmetal.algorithm.multiobjective.moead.MOEAD_DRA">[docs]</a><span class="k">class</span> <span class="nc">MOEAD_DRA</span><span class="p">(</span><span class="n">MOEAD</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">problem</span><span class="p">,</span> <span class="n">population_size</span><span class="p">,</span> <span class="n">mutation</span><span class="p">,</span> <span class="n">crossover</span><span class="p">,</span> <span class="n">aggregative_function</span><span class="p">,</span>
                 <span class="n">neighbourhood_selection_probability</span><span class="p">,</span> <span class="n">max_number_of_replaced_solutions</span><span class="p">,</span> <span class="n">neighbor_size</span><span class="p">,</span>
                 <span class="n">weight_files_path</span><span class="p">,</span> <span class="n">termination_criterion</span><span class="o">=</span><span class="n">store</span><span class="o">.</span><span class="n">default_termination_criteria</span><span class="p">,</span>
                 <span class="n">population_generator</span><span class="o">=</span><span class="n">store</span><span class="o">.</span><span class="n">default_generator</span><span class="p">,</span> <span class="n">population_evaluator</span><span class="o">=</span><span class="n">store</span><span class="o">.</span><span class="n">default_evaluator</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">MOEAD_DRA</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">problem</span><span class="p">,</span> <span class="n">population_size</span><span class="p">,</span> <span class="n">mutation</span><span class="p">,</span> <span class="n">crossover</span><span class="p">,</span> <span class="n">aggregative_function</span><span class="p">,</span>
                                        <span class="n">neighbourhood_selection_probability</span><span class="p">,</span> <span class="n">max_number_of_replaced_solutions</span><span class="p">,</span>
                                        <span class="n">neighbor_size</span><span class="p">,</span> <span class="n">weight_files_path</span><span class="p">,</span>
                                        <span class="n">termination_criterion</span><span class="o">=</span><span class="n">termination_criterion</span><span class="p">,</span>
                                        <span class="n">population_generator</span><span class="o">=</span><span class="n">population_generator</span><span class="p">,</span>
                                        <span class="n">population_evaluator</span><span class="o">=</span><span class="n">population_evaluator</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">saved_values</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">utility</span> <span class="o">=</span> <span class="p">[</span><span class="mf">1.0</span> <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">population_size</span><span class="p">)]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">frequency</span> <span class="o">=</span> <span class="p">[</span><span class="mf">0.0</span> <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">population_size</span><span class="p">)]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">generation_counter</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">order</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">current_order_index</span> <span class="o">=</span> <span class="mi">0</span>

<div class="viewcode-block" id="MOEAD_DRA.init_progress"><a class="viewcode-back" href="../../../../api/algorithm/multiobjective/eas/moead.html#jmetal.algorithm.multiobjective.moead.MOEAD_DRA.init_progress">[docs]</a>    <span class="k">def</span> <span class="nf">init_progress</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">init_progress</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">saved_values</span> <span class="o">=</span> <span class="p">[</span><span class="n">copy</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">solution</span><span class="p">)</span> <span class="k">for</span> <span class="n">solution</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">solutions</span><span class="p">]</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">evaluations</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">population_size</span>
        <span class="k">for</span> <span class="n">solution</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">solutions</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">fitness_function</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">solution</span><span class="o">.</span><span class="n">objectives</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">order</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__tour_selection</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">current_order_index</span> <span class="o">=</span> <span class="mi">0</span>

        <span class="n">observable_data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_observable_data</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">observable</span><span class="o">.</span><span class="n">notify_all</span><span class="p">(</span><span class="o">**</span><span class="n">observable_data</span><span class="p">)</span></div>

<div class="viewcode-block" id="MOEAD_DRA.update_progress"><a class="viewcode-back" href="../../../../api/algorithm/multiobjective/eas/moead.html#jmetal.algorithm.multiobjective.moead.MOEAD_DRA.update_progress">[docs]</a>    <span class="k">def</span> <span class="nf">update_progress</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">update_progress</span><span class="p">()</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">current_order_index</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_order_index</span> <span class="o">==</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">)):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">order</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__tour_selection</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">current_order_index</span> <span class="o">=</span> <span class="mi">0</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">generation_counter</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">generation_counter</span> <span class="o">%</span> <span class="mi">30</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__utility_function</span><span class="p">()</span></div>

<div class="viewcode-block" id="MOEAD_DRA.selection"><a class="viewcode-back" href="../../../../api/algorithm/multiobjective/eas/moead.html#jmetal.algorithm.multiobjective.moead.MOEAD_DRA.selection">[docs]</a>    <span class="k">def</span> <span class="nf">selection</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">population</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="n">S</span><span class="p">]):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">current_subproblem</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">current_order_index</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">current_order_index</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">frequency</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">current_subproblem</span><span class="p">]</span> <span class="o">+=</span> <span class="mi">1</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">neighbor_type</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">choose_neighbor_type</span><span class="p">()</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">neighbor_type</span> <span class="o">==</span> <span class="s1">&#39;NEIGHBOR&#39;</span><span class="p">:</span>
            <span class="n">neighbors</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">neighbourhood</span><span class="o">.</span><span class="n">get_neighbors</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">current_subproblem</span><span class="p">,</span> <span class="n">population</span><span class="p">)</span>
            <span class="n">mating_population</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">selection_operator</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="n">neighbors</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">mating_population</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">selection_operator</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="n">population</span><span class="p">)</span>

        <span class="n">mating_population</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">population</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">current_subproblem</span><span class="p">])</span>

        <span class="k">return</span> <span class="n">mating_population</span></div>

<div class="viewcode-block" id="MOEAD_DRA.get_name"><a class="viewcode-back" href="../../../../api/algorithm/multiobjective/eas/moead.html#jmetal.algorithm.multiobjective.moead.MOEAD_DRA.get_name">[docs]</a>    <span class="k">def</span> <span class="nf">get_name</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s1">&#39;MOEAD-DRA&#39;</span></div>

    <span class="k">def</span> <span class="nf">__utility_function</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">solutions</span><span class="p">)):</span>
            <span class="n">f1</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">fitness_function</span><span class="o">.</span><span class="n">compute</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">solutions</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">objectives</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">neighbourhood</span><span class="o">.</span><span class="n">weight_vectors</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
            <span class="n">f2</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">fitness_function</span><span class="o">.</span><span class="n">compute</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">saved_values</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">objectives</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">neighbourhood</span><span class="o">.</span><span class="n">weight_vectors</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
            <span class="n">delta</span> <span class="o">=</span> <span class="n">f2</span> <span class="o">-</span> <span class="n">f1</span>
            <span class="k">if</span> <span class="n">delta</span> <span class="o">&gt;</span> <span class="mf">0.001</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">utility</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="mf">1.0</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">utility_value</span> <span class="o">=</span> <span class="p">(</span><span class="mf">0.95</span> <span class="o">+</span> <span class="p">(</span><span class="mf">0.05</span> <span class="o">*</span> <span class="n">delta</span> <span class="o">/</span> <span class="mf">0.001</span><span class="p">))</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">utility</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">utility</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">utility_value</span> <span class="k">if</span> <span class="n">utility_value</span> <span class="o">&lt;</span> <span class="mf">1.0</span> <span class="k">else</span> <span class="mf">1.0</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">saved_values</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">solutions</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>

    <span class="k">def</span> <span class="nf">__tour_selection</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">depth</span><span class="p">):</span>
        <span class="n">selected</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">problem</span><span class="o">.</span><span class="n">number_of_objectives</span><span class="p">)]</span>
        <span class="n">candidate</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">problem</span><span class="o">.</span><span class="n">number_of_objectives</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">population_size</span><span class="p">)]</span>

        <span class="k">while</span> <span class="nb">len</span><span class="p">(</span><span class="n">selected</span><span class="p">)</span> <span class="o">&lt;</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">population_size</span> <span class="o">/</span> <span class="mf">5.0</span><span class="p">):</span>
            <span class="n">best_idd</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">()</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">candidate</span><span class="p">))</span>
            <span class="n">best_sub</span> <span class="o">=</span> <span class="n">candidate</span><span class="p">[</span><span class="n">best_idd</span><span class="p">]</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">depth</span><span class="p">):</span>
                <span class="n">i2</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">()</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">candidate</span><span class="p">))</span>
                <span class="n">s2</span> <span class="o">=</span> <span class="n">candidate</span><span class="p">[</span><span class="n">i2</span><span class="p">]</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">utility</span><span class="p">[</span><span class="n">s2</span><span class="p">]</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">utility</span><span class="p">[</span><span class="n">best_sub</span><span class="p">]:</span>
                    <span class="n">best_idd</span> <span class="o">=</span> <span class="n">i2</span>
                    <span class="n">best_sub</span> <span class="o">=</span> <span class="n">s2</span>
            <span class="n">selected</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">best_sub</span><span class="p">)</span>
            <span class="k">del</span> <span class="n">candidate</span><span class="p">[</span><span class="n">best_idd</span><span class="p">]</span>

        <span class="k">return</span> <span class="n">selected</span></div>


<div class="viewcode-block" id="MOEADIEpsilon"><a class="viewcode-back" href="../../../../api/algorithm/multiobjective/eas/moead.html#jmetal.algorithm.multiobjective.moead.MOEADIEpsilon">[docs]</a><span class="k">class</span> <span class="nc">MOEADIEpsilon</span><span class="p">(</span><span class="n">MOEAD</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
                 <span class="n">problem</span><span class="p">:</span> <span class="n">Problem</span><span class="p">,</span>
                 <span class="n">population_size</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span>
                 <span class="n">mutation</span><span class="p">:</span> <span class="n">Mutation</span><span class="p">,</span>
                 <span class="n">crossover</span><span class="p">:</span> <span class="n">DifferentialEvolutionCrossover</span><span class="p">,</span>
                 <span class="n">aggregative_function</span><span class="p">:</span> <span class="n">AggregativeFunction</span><span class="p">,</span>
                 <span class="n">neighbourhood_selection_probability</span><span class="p">:</span> <span class="nb">float</span><span class="p">,</span>
                 <span class="n">max_number_of_replaced_solutions</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span>
                 <span class="n">neighbor_size</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span>
                 <span class="n">weight_files_path</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
                 <span class="n">termination_criterion</span><span class="p">:</span> <span class="n">TerminationCriterion</span> <span class="o">=</span> <span class="n">StoppingByEvaluations</span><span class="p">(</span><span class="mi">300000</span><span class="p">),</span>
                 <span class="n">population_generator</span><span class="p">:</span> <span class="n">Generator</span> <span class="o">=</span> <span class="n">store</span><span class="o">.</span><span class="n">default_generator</span><span class="p">,</span>
                 <span class="n">population_evaluator</span><span class="p">:</span> <span class="n">Evaluator</span> <span class="o">=</span> <span class="n">store</span><span class="o">.</span><span class="n">default_evaluator</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :param max_number_of_replaced_solutions: (eta in Zhang &amp; Li paper).</span>
<span class="sd">        :param neighbourhood_selection_probability: Probability of mating with a solution in the neighborhood rather</span>
<span class="sd">               than the entire population (Delta in Zhang &amp; Li paper).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">MOEADIEpsilon</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span>
            <span class="n">problem</span><span class="o">=</span><span class="n">problem</span><span class="p">,</span>
            <span class="n">population_size</span><span class="o">=</span><span class="n">population_size</span><span class="p">,</span>
            <span class="n">mutation</span><span class="o">=</span><span class="n">mutation</span><span class="p">,</span>
            <span class="n">crossover</span><span class="o">=</span><span class="n">crossover</span><span class="p">,</span>
            <span class="n">aggregative_function</span><span class="o">=</span><span class="n">aggregative_function</span><span class="p">,</span>
            <span class="n">neighbourhood_selection_probability</span><span class="o">=</span><span class="n">neighbourhood_selection_probability</span><span class="p">,</span>
            <span class="n">max_number_of_replaced_solutions</span><span class="o">=</span><span class="n">max_number_of_replaced_solutions</span><span class="p">,</span>
            <span class="n">neighbor_size</span><span class="o">=</span><span class="n">neighbor_size</span><span class="p">,</span>
            <span class="n">weight_files_path</span><span class="o">=</span><span class="n">weight_files_path</span><span class="p">,</span>
            <span class="n">population_evaluator</span><span class="o">=</span><span class="n">population_evaluator</span><span class="p">,</span>
            <span class="n">population_generator</span><span class="o">=</span><span class="n">population_generator</span><span class="p">,</span>
            <span class="n">termination_criterion</span><span class="o">=</span><span class="n">termination_criterion</span>
        <span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">constraints</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">epsilon_k</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">phi_max</span> <span class="o">=</span> <span class="o">-</span><span class="mf">1e30</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">epsilon_zero</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tc</span> <span class="o">=</span> <span class="mi">800</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tao</span> <span class="o">=</span> <span class="mf">0.05</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">rk</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">generation_counter</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">archive</span> <span class="o">=</span> <span class="p">[]</span>

<div class="viewcode-block" id="MOEADIEpsilon.init_progress"><a class="viewcode-back" href="../../../../api/algorithm/multiobjective/eas/moead.html#jmetal.algorithm.multiobjective.moead.MOEADIEpsilon.init_progress">[docs]</a>    <span class="k">def</span> <span class="nf">init_progress</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">init_progress</span><span class="p">()</span>

        <span class="c1"># for i in range(self.population_size):</span>
        <span class="c1">#    self.constraints[i] = get_overall_constraint_violation_degree(self.permutation[i])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">constraints</span> <span class="o">=</span> <span class="p">[</span><span class="n">overall_constraint_violation_degree</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">solutions</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
                            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">population_size</span><span class="p">)]</span>

        <span class="nb">sorted</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">constraints</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">epsilon_zero</span> <span class="o">=</span> <span class="nb">abs</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">constraints</span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">ceil</span><span class="p">(</span><span class="mf">0.05</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">population_size</span><span class="p">))])</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">phi_max</span> <span class="o">&lt;</span> <span class="nb">abs</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">constraints</span><span class="p">[</span><span class="mi">0</span><span class="p">]):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">phi_max</span> <span class="o">=</span> <span class="nb">abs</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">constraints</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">rk</span> <span class="o">=</span> <span class="n">feasibility_ratio</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">solutions</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">epsilon_k</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">epsilon_zero</span></div>

<div class="viewcode-block" id="MOEADIEpsilon.update_progress"><a class="viewcode-back" href="../../../../api/algorithm/multiobjective/eas/moead.html#jmetal.algorithm.multiobjective.moead.MOEADIEpsilon.update_progress">[docs]</a>    <span class="k">def</span> <span class="nf">update_progress</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">update_progress</span><span class="p">()</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">evaluations</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">population_size</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">update_external_archive</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">generation_counter</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">rk</span> <span class="o">=</span> <span class="n">feasibility_ratio</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">solutions</span><span class="p">)</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">generation_counter</span> <span class="o">&gt;=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tc</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">epsilon_k</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">rk</span> <span class="o">&lt;</span> <span class="mf">0.95</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">epsilon_k</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">tao</span><span class="p">)</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">epsilon_k</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">epsilon_k</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">phi_max</span> <span class="o">*</span> <span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">tao</span><span class="p">)</span></div>

<div class="viewcode-block" id="MOEADIEpsilon.update_current_subproblem_neighborhood"><a class="viewcode-back" href="../../../../api/algorithm/multiobjective/eas/moead.html#jmetal.algorithm.multiobjective.moead.MOEADIEpsilon.update_current_subproblem_neighborhood">[docs]</a>    <span class="k">def</span> <span class="nf">update_current_subproblem_neighborhood</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">new_solution</span><span class="p">,</span> <span class="n">population</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">phi_max</span> <span class="o">&lt;</span> <span class="n">overall_constraint_violation_degree</span><span class="p">(</span><span class="n">new_solution</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">phi_max</span> <span class="o">=</span> <span class="n">overall_constraint_violation_degree</span><span class="p">(</span><span class="n">new_solution</span><span class="p">)</span>

        <span class="n">permuted_neighbors_indexes</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">generate_permutation_of_neighbors</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">current_subproblem</span><span class="p">)</span>
        <span class="n">replacements</span> <span class="o">=</span> <span class="mi">0</span>

        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">permuted_neighbors_indexes</span><span class="p">)):</span>
            <span class="n">k</span> <span class="o">=</span> <span class="n">permuted_neighbors_indexes</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>

            <span class="n">f1</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">fitness_function</span><span class="o">.</span><span class="n">compute</span><span class="p">(</span><span class="n">population</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">.</span><span class="n">objectives</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">neighbourhood</span><span class="o">.</span><span class="n">weight_vectors</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
            <span class="n">f2</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">fitness_function</span><span class="o">.</span><span class="n">compute</span><span class="p">(</span><span class="n">new_solution</span><span class="o">.</span><span class="n">objectives</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">neighbourhood</span><span class="o">.</span><span class="n">weight_vectors</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>

            <span class="n">cons1</span> <span class="o">=</span> <span class="nb">abs</span><span class="p">(</span><span class="n">overall_constraint_violation_degree</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">solutions</span><span class="p">[</span><span class="n">k</span><span class="p">]))</span>
            <span class="n">cons2</span> <span class="o">=</span> <span class="nb">abs</span><span class="p">(</span><span class="n">overall_constraint_violation_degree</span><span class="p">(</span><span class="n">new_solution</span><span class="p">))</span>

            <span class="k">if</span> <span class="n">cons1</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">epsilon_k</span> <span class="ow">and</span> <span class="n">cons2</span> <span class="o">&lt;=</span> <span class="bp">self</span><span class="o">.</span><span class="n">epsilon_k</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">f2</span> <span class="o">&lt;</span> <span class="n">f1</span><span class="p">:</span>
                    <span class="n">population</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">(</span><span class="n">new_solution</span><span class="p">)</span>
                    <span class="n">replacements</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="k">elif</span> <span class="n">cons1</span> <span class="o">==</span> <span class="n">cons2</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">f2</span> <span class="o">&lt;</span> <span class="n">f1</span><span class="p">:</span>
                    <span class="n">population</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">(</span><span class="n">new_solution</span><span class="p">)</span>
                    <span class="n">replacements</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="k">elif</span> <span class="n">cons2</span> <span class="o">&lt;</span> <span class="n">cons1</span><span class="p">:</span>
                <span class="n">population</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">(</span><span class="n">new_solution</span><span class="p">)</span>
                <span class="n">replacements</span> <span class="o">+=</span> <span class="mi">1</span>

            <span class="k">if</span> <span class="n">replacements</span> <span class="o">&gt;=</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_number_of_replaced_solutions</span><span class="p">:</span>
                <span class="k">break</span>

        <span class="k">return</span> <span class="n">population</span></div>

<div class="viewcode-block" id="MOEADIEpsilon.update_external_archive"><a class="viewcode-back" href="../../../../api/algorithm/multiobjective/eas/moead.html#jmetal.algorithm.multiobjective.moead.MOEADIEpsilon.update_external_archive">[docs]</a>    <span class="k">def</span> <span class="nf">update_external_archive</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">feasible_solutions</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">solution</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">solutions</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">is_feasible</span><span class="p">(</span><span class="n">solution</span><span class="p">):</span>
                <span class="n">feasible_solutions</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">copy</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">(</span><span class="n">solution</span><span class="p">))</span>

        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">feasible_solutions</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">feasible_solutions</span> <span class="o">=</span> <span class="n">feasible_solutions</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">archive</span>
            <span class="n">ranking</span> <span class="o">=</span> <span class="n">FastNonDominatedRanking</span><span class="p">()</span>
            <span class="n">ranking</span><span class="o">.</span><span class="n">compute_ranking</span><span class="p">(</span><span class="n">feasible_solutions</span><span class="p">)</span>

            <span class="n">first_rank_solutions</span> <span class="o">=</span> <span class="n">ranking</span><span class="o">.</span><span class="n">get_subfront</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">first_rank_solutions</span><span class="p">)</span> <span class="o">&lt;=</span> <span class="bp">self</span><span class="o">.</span><span class="n">population_size</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">archive</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="k">for</span> <span class="n">solution</span> <span class="ow">in</span> <span class="n">first_rank_solutions</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">archive</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">copy</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">(</span><span class="n">solution</span><span class="p">))</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">crowding_distance</span> <span class="o">=</span> <span class="n">CrowdingDistance</span><span class="p">()</span>
                <span class="k">while</span> <span class="nb">len</span><span class="p">(</span><span class="n">first_rank_solutions</span><span class="p">)</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">population_size</span><span class="p">:</span>
                    <span class="n">crowding_distance</span><span class="o">.</span><span class="n">compute_density_estimator</span><span class="p">(</span><span class="n">first_rank_solutions</span><span class="p">)</span>
                    <span class="n">first_rank_solutions</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">first_rank_solutions</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">attributes</span><span class="p">[</span><span class="s1">&#39;crowding_distance&#39;</span><span class="p">],</span>
                                                  <span class="n">reverse</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
                    <span class="n">first_rank_solutions</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span>

                <span class="bp">self</span><span class="o">.</span><span class="n">archive</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="k">for</span> <span class="n">solution</span> <span class="ow">in</span> <span class="n">first_rank_solutions</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">archive</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">copy</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">(</span><span class="n">solution</span><span class="p">))</span></div>

<div class="viewcode-block" id="MOEADIEpsilon.get_result"><a class="viewcode-back" href="../../../../api/algorithm/multiobjective/eas/moead.html#jmetal.algorithm.multiobjective.moead.MOEADIEpsilon.get_result">[docs]</a>    <span class="k">def</span> <span class="nf">get_result</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">archive</span></div></div>


<div class="viewcode-block" id="Permutation"><a class="viewcode-back" href="../../../../api/algorithm/multiobjective/eas/moead.html#jmetal.algorithm.multiobjective.moead.Permutation">[docs]</a><span class="k">class</span> <span class="nc">Permutation</span><span class="p">:</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">length</span><span class="p">:</span> <span class="nb">int</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">counter</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">length</span> <span class="o">=</span> <span class="n">length</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">permutation</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">permutation</span><span class="p">(</span><span class="n">length</span><span class="p">)</span>

<div class="viewcode-block" id="Permutation.get_next_value"><a class="viewcode-back" href="../../../../api/algorithm/multiobjective/eas/moead.html#jmetal.algorithm.multiobjective.moead.Permutation.get_next_value">[docs]</a>    <span class="k">def</span> <span class="nf">get_next_value</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">next_value</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">permutation</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">counter</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">counter</span> <span class="o">+=</span> <span class="mi">1</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">counter</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">length</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">permutation</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">permutation</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">length</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">counter</span> <span class="o">=</span> <span class="mi">0</span>

        <span class="k">return</span> <span class="n">next_value</span></div>

<div class="viewcode-block" id="Permutation.get_permutation"><a class="viewcode-back" href="../../../../api/algorithm/multiobjective/eas/moead.html#jmetal.algorithm.multiobjective.moead.Permutation.get_permutation">[docs]</a>    <span class="k">def</span> <span class="nf">get_permutation</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">permutation</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span></div></div>
</pre></div>

          </div>
            
        </div>
        <div class="clearfix"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">jMetalPy 1.5.1 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li> 
      </ul>
    </div>
<script type="text/javascript">
  $("#mobile-toggle a").click(function () {
    $("#left-column").toggle();
  });
</script>
<script type="text/javascript" src="../../../../_static/js/bootstrap.js"></script>
  <div class="footer">
    &copy; Copyright 2019, Antonio Benítez-Hidalgo. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
  </div>
  </body>
</html>